package com.shou.trigger.http.mapstruct;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shou.api.model.dto.ParkingSpaceDTO;
import com.shou.domain.park.model.ParkingSpaceEntity;
import org.mapstruct.Mapper;

import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName:ParkingSpaceDTOConvert
 * Project:SmartPark
 * Package: com.shou.trigger.http.mapstruct
 * Description
 *
 * @Author Nemo
 * @Create 2025/2/8 17:38
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface ParkingSpaceDTOConvert {
    ParkingSpaceEntity convertParkingSpaceDTOToEntity(ParkingSpaceDTO rule);
    ParkingSpaceDTO convertParkingSpaceEntityToDTO(ParkingSpaceEntity rule);

    default IPage<ParkingSpaceDTO> convertParkingSpaceEntityPageToDTO(IPage<ParkingSpaceEntity> pageMessage){
        if (pageMessage == null || pageMessage.getRecords() == null || pageMessage.getRecords().isEmpty()) {
            return null;
        }
        List<ParkingSpaceDTO> pageMessageEntities = pageMessage.getRecords().stream()
                .map(this::convertParkingSpaceEntityToDTO)
                .collect(Collectors.toList());

        IPage<ParkingSpaceDTO> entityPage = new Page<>();
        entityPage.setRecords(pageMessageEntities);
        entityPage.setTotal(pageMessage.getTotal());
        entityPage.setSize(pageMessage.getSize());
        entityPage.setCurrent(pageMessage.getCurrent());
        return entityPage;
    }
}
